package com.tjh.springbootapi.aspect;

import com.tjh.springbootapi.annotation.AopAnnotation;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * Create by koala on 2022-08-11
 */
@Aspect
@Component
public class AopAnnotationAspect {

    @Pointcut("@annotation(com.tjh.springbootapi.annotation.AopAnnotation)")
    public void aopAnnotationCut() {
    }

    @After("aopAnnotationCut()")
    public void action(JoinPoint point) {
        MethodSignature signature = (MethodSignature) point.getSignature();
        AopAnnotation aopAnnotation = signature.getMethod().getAnnotation(AopAnnotation.class);
        String code = aopAnnotation.code();
        System.out.println("获取到的方法注解值为：" + code);

        //TODO 可以给返回值中塞数据 /对返回结果进行特殊处理 等等功能
    }
}